<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="/~meierj/uml/uml/Styles/style.css" />
        <meta charset="utf-8" />
        <title>UML-Team</title>
    </head>
    <body>

        <?php
        include ('/home/ann2/meierj/public_html/uml/uml/Includes/header.php');
        include ('/home/ann2/meierj/public_html/uml/uml/Includes/formulaire.php');
        include ('/home/ann2/meierj/public_html/uml/uml/Includes/menu.php');
        ?>

        <div id="corps">
            <h1>
                Inscription
            </h1>
            <!-- FORMULAIRE INSCRIPTION -->
            <div id="formulaire">
                <form method="post" action="#">
                    <p>
                        <input type="text" placeholder="Nom" name="nom" value="<?php
                        if (isset($_POST['nom'])) {
                            echo htmlentities($_POST['nom']);
                        }
                        ?>" />
                    </p>
                    <p>
                        <input type="text" placeholder="Prénom" name="prenom" value="<?php
                        if (isset($_POST['prenom'])) {
                            echo htmlentities($_POST['prenom']);
                        }
                        ?>" />
                    </p>
                    <p>
                        <input type="text" placeholder="Mail" value="<?php
                        if (isset($_POST['mail'])) {
                            echo htmlentities($_POST['mail']);
                        }
                        ?>" name="mail" id="mail" />
                    </p>
                    <p>
                        <input type="password" placeholder="Mot de passe" value="<?php
                        if (isset($_POST['mdp'])) {
                            echo htmlentities($_POST['mdp']);
                        }
                        ?>" name="mdp" />
                    </p>
                    <p>
                        <input type="password" value="<?php
                        if (isset($_POST['mdp2'])) {
                            echo htmlentities($_POST['mdp2']);
                        }
                        ?>" placeholder="Vérification mot de passe" name="mdp2" />
                    </p>
                    <p>
                        <input type="submit" value="OK" name="insc" />
                    </p>
                </form>
            </div>	



            <!-- CODE PHP : INSCRIPTION -->
            <?php
            $form = true;
            $message = null;
            // Si le formulaire est envoyé
            if (!empty($_POST['insc'])) {
                $_POST['mdp'] = trim($_POST['mdp']);
                $_POST['mdp2'] = trim($_POST['mdp2']);
                $_POST['nom'] = trim($_POST['nom']);
                $_POST['prenom'] = trim($_POST['prenom']);
                $_POST['mail'] = trim($_POST['mail']);
                if (!empty($_POST['mdp']) && $_POST['mdp'] != null) {
                    if (!empty($_POST['mdp2']) && $_POST['mdp2'] != null) {
                        if (!empty($_POST['nom']) && $_POST['nom'] != null) {
                            if (!empty($_POST['prenom']) && $_POST['prenom'] != null) {
                                if ($_POST['mail'] && preg_match('#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#', $_POST['mail'])) {
                                    //tous les champs ont été saisis
                                    if ($_POST['mdp'] == $_POST['mdp2']) {
                                        //verification mdp OK
                                        //récupération des variables
                                        $mdp = $_POST['mdp'];
                                        $mdp = md5($mdp);
                                        $mail = $_POST['mail'];
                                        $nom = $_POST['nom'];
                                        $prenom = $_POST['prenom'];
                                        //     require('/home/ann2/meierj/public_html/uml/uml/controleur.php');
                                        ajoutMembre($mail, $nom, $prenom, $mdp);
                                    } else {
                                        $form = true;
                                        $message = 'Merci de saisir deux mots de passe identiques';
                                    }
                                } else {
                                    $form = true;
                                    $message = 'Merci de saisir un email valide';
                                }
                            } else {
                                $form = true;
                                $message = 'Merci de saisir votre prénom';
                            }
                        } else {
                            $form = true;
                            $message = 'Merci de saisir votre nom';
                        }
                    } else {
                        $form = true;
                        $message = 'Merci de saisir le champs de vérification du mot de passe';
                    }
                } else {
                    $form = true;
                    $message = 'Merci de saisir votre mot de passe';
                }
            }

            if ($form) {
                echo $message;
            }
            ?>


        </div>
    </body>
</html>

